<?php require_once('Connections/CSRE_Connection.php'); ?>
<?php include('CSRE_login_control.php') ?>

<table width="100%" class="text_form" cellspacing="0" cellpadding="3" 
	 style="border: #5995CA thin solid; font-family:Verdana, Arial, Helvetica, sans-serif;">
	<thead style="background-color: #8EA5D9; color:#FFFFFF; font-weight:bold;">
		<tr align="center">
			<td>No. CSRE Produit</td>
			<td>Nom du Produit </td>
			<td>Qt&eacute;</td>
			<td>Co&ucirc;t</td>
			<td>Taxable</td>
			<td>Total</td>
		</tr>
	</thead>
	<?php 


	
	if (isset($_SESSION["products"])) {

		$total = 0;
		$keys = array_keys($_SESSION["products"]);
		

		
		foreach ($keys as $key) {
			mysql_select_db($database_CSRE_Connection, $CSRE_Connection);
			$query_productById = sprintf("SELECT * FROM csre_product WHERE product_id = %s", $key);
			$productById = mysql_query($query_productById, $CSRE_Connection) or die(mysql_error());
			$row_productById = mysql_fetch_assoc($productById);
			$totalRows_productById = mysql_num_rows($productById);
	?>

	<tr>
		
		<td>
			<?php echo $row_productById['csre_number']; ?>		</td>
		
		<td>
			<?php echo $row_productById['name_FR']; ?>		</td>
		
		<td>
			<table width="100">
				<tr>
					<td align="right">
					<input type="text" name="cant_<?php echo $key; ?>" id="cant_<?php echo $key; ?>"
						value="<?php echo $_SESSION["products"][$key]['units']; ?>" 
						onBlur="changeCant(this.id, this); 
							Ajax('CSRE_checkout_product_table.php','paso2_products');
							Ajax('CSRE_checkout_subtotal.php','paso2_totals');"
						style="width: 50px;" />					</td>
					<td>
						<img src="images/csre/1305990737_DeleteRed.png"
							onclick="deleteProd(<?php echo $row_productById['product_id'];  ?>); 
								Ajax('CSRE_checkout_product_table.php', 'paso2_products');
								Ajax('CSRE_checkout_subtotal.php','paso2_totals');">					</td>
				</tr>
			</table>	    </td>
		
		<td align="right">
			$&nbsp;<?php echo number_format($row_productById['price'] ,2,',','.'); ?>	    </td>

		<td align="center">
			<?php if ($row_productById['taxable'] == 1) { echo "Oui"; } else { echo "Non"; } ?>
		</td>

		<td align="right" width="100">
			$&nbsp;
				<?php echo number_format(($_SESSION["products"][$key]['units'] * $row_productById['price']) ,2,',','.'); 
					$total = $total + $_SESSION["products"][$key]['units'] * $row_productById['price']; ?>		</td>
	</tr>
	<tr>
		<td colspan="5">
			<?php echo $row_productById['details_FR']; ?>		</td>
	</tr>
	<tr>
		<td colspan="5">
			<?php
				mysql_select_db($database_CSRE_Connection, $CSRE_Connection);
				$query_services = sprintf("SELECT t.type_id as type_id, t.description as description FROM csre_serv_types t 
					where t.type_id in (select sp.type_id from csre_prod_service sp where sp.product_id = %s) 
					ORDER BY type_id ASC",  $key);
				$services = mysql_query($query_services, $CSRE_Connection) or die(mysql_error());
				$row_services = mysql_fetch_assoc($services);
				$totalRows_services = mysql_num_rows($services);
			
//			echo "serv " . $_SESSION["products"][$key]["service"];
			?>
			
			
			
			<select name="serv_<?php echo $key; ?>" id="serv_<?php echo $key; ?>"
				onchange="changeServ(this.id); 
							Ajax('CSRE_checkout_product_table.php','paso2_products');
							Ajax('CSRE_checkout_subtotal.php','paso2_totals');">
         
		 		  <?php do { ?>
         				
					  <option value="<?php echo $row_services['type_id']; ?>" 
					 
						  <?php if ($row_services['type_id'] == $_SESSION["products"][$key]["service"]) { echo "selected='selected'"; } ?>>
						  <?php echo $row_services['description']?>
					  </option>
				  <?php } while ($row_services = mysql_fetch_assoc($services)); 
				  	mysql_free_result($services);
				  ?>
        	</select>
						
		</td>
	</tr>
	<tr>
		<td colspan="6" style="border-bottom: #999999 solid thin; height:1px;"></td>
	</tr>
	<?php
		}

	}
	?>
</table>
